#include "AABB.h"

float AABB::getHullSize(void) const
{
	const float sizeX = max.x - min.x;
	const float sizeY = max.y - min.y;
	const float sizeZ = max.z - min.z;
	return 2 * (sizeX * sizeY + sizeX * sizeZ + sizeY * sizeZ);
}

float AABB::getLeftHullSize(const float split, const int axis) const
{
	const float maxX = (axis == X) ? split : max.x;
	const float maxY = (axis == Y) ? split : max.y;
	const float maxZ = (axis == Z) ? split : max.z;

	const float sizeX = maxX - min.x;
	const float sizeY = maxY - min.y;
	const float sizeZ = maxZ - min.z;
	return 2 * (sizeX * sizeY + sizeX * sizeZ + sizeY * sizeZ);
}

float AABB::getRightHullSize(const float split, const int axis) const
{
	const float minX = (axis == X) ? split : min.x;
	const float minY = (axis == Y) ? split : min.y;
	const float minZ = (axis == Z) ? split : min.z;

	const float sizeX = max.x - minX;
	const float sizeY = max.y - minY;
	const float sizeZ = max.z - minZ;
	return 2 * (sizeX * sizeY + sizeX * sizeZ + sizeY * sizeZ);
}

int AABB::getMaxAxis(void) const
{
	const float sizeX = max.x - min.x;
	const float sizeY = max.y - min.y;
	const float sizeZ = max.z - min.z;
	
	return (sizeX > sizeY) ? ((sizeX > sizeZ) ? X : Z) : ((sizeY > sizeZ) ? Y : Z);
}

AABB AABB::createLeft(const float split, const int axis) const
{
	const float maxX = (axis == X) ? split : max.x;
	const float maxY = (axis == Y) ? split : max.y;
	const float maxZ = (axis == Z) ? split : max.z;

	return AABB(min, SPoint(maxX, maxY, maxZ));
}

AABB AABB::createRight(const float split, const int axis) const
{
	const float minX = (axis == X) ? split : min.x;
	const float minY = (axis == Y) ? split : min.y;
	const float minZ = (axis == Z) ? split : min.z;

	return AABB(SPoint(minX, minY, minZ), max);
}
